﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SpringStudio.Common;
using SpringStudio.DAL.PaginationHandler;
using Sdepci.InfoCode.BLL.CodeDesign;

namespace Sdepci.InfoCode.Web.CodeDesign
{
    public partial class TypeRuleList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.ViewState["MyGridTemplate"] = this.MyGridTemplate.InnerHtml;
                this.BindData();
            }
        }

        /// <summary>
        /// 绑定数据列表
        /// </summary>
        private void BindData()
        {
            this.MyGridTemplate.InnerHtml = MyGrid.DsToHtml(new TypeRuleManager().GetTypeRuleDs(), this.ViewState["MyGridTemplate"].ToString());
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.Request.Form["ItemId"] != null)
            {
                TypeRuleManager typeRuleManager = new TypeRuleManager();
                string[] ruleGuids = this.Request.Form["ItemId"].ToString().Split(',');
                bool result = true;
                for (int i = 0; i < ruleGuids.Length; i++)
                {
                    if (!typeRuleManager.Delete(ruleGuids[i]))
                    {
                        result = false;
                    }
                }

                string msg = result ? "删除完成！" : "操作完成，但未能把所选项目全部删除，请查看错误日志！";
                this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script language=\"javascript\">alert(\"" + msg + "\");</script>");
                this.BindData();
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            this.Response.Redirect("TypeRuleEdit.aspx");
        }

        protected void btnModify_Click(object sender, EventArgs e)
        {
            if (this.Request.Form["ItemId"] != null)
            {
                this.Response.Redirect("TypeRuleEdit.aspx?RuleGuid=" + this.Request.Form["ItemId"].ToString().Split(',')[0]);
            }
        }
    }
}
